//
//  TabBarViewController.m
//  TingLiFeng
//
//  Created by xinxuan on 16/1/3.
//  Copyright © 2016年 xinxuan. All rights reserved.
//

#import "TabBarViewController.h"
#import "HomeViewController.h"
#import "MeViewController.h"
#import "HotViewController.h"
#import "RecommendViewController.h"
#import "NavigationViewController.h"
@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addSubControllers];
}

-(void)addSubControllers{
    
    HomeViewController * homeVC = [[HomeViewController alloc] init];
    [self addOneChlidVc:homeVC  title:@"发现课程" imgName:@"发现" selectedImageName:@"发现点击"];
    
    RecommendViewController * recommendVC = [[RecommendViewController alloc] init];
    [self addOneChlidVc:recommendVC  title:@"推荐课程" imgName:@"排名" selectedImageName:@"排名点击"];
    
    
    HotViewController * hotVC = [[HotViewController alloc] init];
    [self addOneChlidVc:hotVC  title:@"最火" imgName:@"最火" selectedImageName:@"最火点击"];
    
    
    MeViewController * meVC = [[MeViewController alloc] init];
    [self addOneChlidVc:meVC  title:@"我" imgName:@"我" selectedImageName:@"我点击"];
    
}


//添加一个子控制器
-(void)addOneChlidVc:(UIViewController*)chlidVc title:(NSString*)title imgName:(NSString*)imageName selectedImageName:(NSString*)selectedImageName{

    //设置tabBarItem的选中文字颜色
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
    [chlidVc.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    
    //设置标题
    //chlidVc.title = title;//相当于同时设置tabBarItem.title 和navigationItem.title
    //    chlidVc.tabBarItem.title = title;
    
        chlidVc.navigationItem.title = title;
    //设置图标
    chlidVc.tabBarItem.image = [[UIImage imageNamed:imageName]imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)];
    //设置选中的图标
    UIImage * selectedImage = [UIImage imageNamed:selectedImageName];
    if (iOS7) {//渲染,永远保持原来的状态
        selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    chlidVc.tabBarItem.selectedImage = selectedImage;    //添加tabbar控制器的子控制器
    chlidVc.tabBarItem.imageInsets=UIEdgeInsetsMake(6, 0,-6, 0);//调整tabBar的位置
    NavigationViewController * nav = [[NavigationViewController alloc]initWithRootViewController:chlidVc];
   
    [self addChildViewController:nav];
    
}


@end
